﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using WcfContrib.Client.Behaviors;

namespace WcfContrib.Client.Description
{
    /// <summary>
    /// Represents a client channel endpoint description
    /// </summary>
    public sealed class ClientEndpointDescription
    {
        /// <summary>
        /// Gets the endpoint behaviors.
        /// </summary>
        /// <value>The behaviors.</value>
        public DescriptionCollection<IClientEndpointBehavior> Behaviors { get; private set; }
        /// <summary>
        /// Gets the channel handlers.
        /// </summary>
        /// <value>The channel handlers.</value>
        public DescriptionCollection<IClientChannelHandlerBehavior> ChannelHandlers { get; private set; }

        /// <summary>
        /// Gets or sets the channel provider.
        /// </summary>
        /// <value>The channel provider.</value>
        public IChannelProvider ChannelProvider { get; set; }

        /// <summary>
        /// Gets the contract description.
        /// </summary>
        /// <value>The contract.</value>
        public ClientContractDescription Contract { get; private set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="ClientEndpointDescription"/> class.
        /// </summary>
        /// <param name="channel">The client channel.</param>
        /// <param name="contract">The contract description.</param>
        public ClientEndpointDescription(ClientChannel channel, ClientContractDescription contract)
        {
            Behaviors = new DescriptionCollection<IClientEndpointBehavior>();
            ChannelHandlers = new DescriptionCollection<IClientChannelHandlerBehavior>();

            Contract = contract;

            ChannelProvider = new DefaultChannelProvider(channel);

            Behaviors.ItemAdded = b => b.ApplyClientBehavior(channel, this);
        }
    }
}
